-
Notifications
You must be signed in to change notification settings - Fork 22
CF 680 don't emit unnecessary warning & improve UX when using cmd init #487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
| logger.error( | ||
| f"CF_API_Error:: making request to Codeflash API (url: {url}, method: {method}, status {response.status_code}): {error_message}" | ||
| ) | ||
| if not suppress_errors: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Why are we suppressing the errors?
…(`better-UX`)
Here are targeted and *safe* optimizations for your code, focusing primarily on the **parse_config_file** function, since it dominates the runtime (~98% of `should_modify_pyproject_toml`).
The main bottlenecks per the profile are both TOML parsing (external, little to be optimized from user code) and the __massive number of slow in-place config key conversions__ (`config[key.replace("-", "_")] = config[key]; del config[key]`).
Most of the `key in config` lookups and repeated work can be reduced by processing keys more efficiently in fewer iterations.
**Key Optimizations:**
1. **Single Pass Normalization:**
Instead of scanning the dictionary repeatedly converting hyphens to underscores, process the keys in-place in a single pass, creating a new dict with both normalized and original keys pointing to the same value, replacing `config`.
This is faster and safe.
2. **Batch Default Handling:**
Instead of sequentially modifying for each key + default type, merge in default values for all missing keys at once using `.setdefault`.
3. **Avoid Excessive Path Conversion/Resolving:**
Convert/resolve each path once, only if present, and do not build new `Path` objects multiple times.
4. **Minimize Repeated `Path(...).parent` Calculations:**
Compute parent once.
5. **Optimize `[str(cmd) for cmd in config[key]]`:**
Move path computations and casting to lists earlier, minimize unnecessary transformations.
6. **Re-use objects and variables rather than repeated lookups.**
7. **Pre-filter config keys for path work.**
No changes to behavior or function signatures.
**All existing comments are kept where relevant.**
Here is your optimized, drop-in replacement.
**Summary of changes:**
- Dramatically reduced config dict key normalization cost (single scan, not per key).
- Minimized resolve/path operations, and batch-applied defaults.
- The rest of the logic and all comments are unchanged.
- No change to function names or signatures.
This version will significantly reduce the overhead in `parse_config_file` due to a much more efficient key normalization and default merging logic.
If you want even more speed, consider switching from `tomlkit` to `tomllib` for TOML parsing if you do not require preservation of comments or formatting.
⚡️ Codeflash found optimizations for this PR📄 146% (1.46x) speedup for
|


PR Type
Enhancement
Description
Introduce
suppress_errorsflag in CF API requestsSuppress error logging when flag is enabled
Update CLI GitHub app installer to use suppression
Clean up LSP server formatting and docs
Changes walkthrough 📝
cfapi.py
Add suppress_errors flag for API requestscodeflash/api/cfapi.py
suppress_errorsparameter tomake_cfapi_requestsuppress_errorsis_github_app_installed_on_reposignature and callssuppress_errorsin function docstringcmd_init.py
Use suppress_errors in installer checkscodeflash/cli_cmds/cmd_init.py
suppress_errors=Trueto install checksserver.py
Format imports and docstringscodeflash/lsp/server.py
MessageType,LogMessageParams)show_message_logdocstring formattingserver_entry.py
Refine docstring and type annotationcodeflash/lsp/server_entry.py
setup_logging